package com.example.batch

import org.apache.flink.api.scala.{ExecutionEnvironment, createTypeInformation}

/**
 * @author lbq
 * @date 2022/3/14 22:38
 * @version 1.0
 */
object WordCountScala {

  val input_path = "data/input/text.txt"
  val output_path = "data/output/result.csv"

  def main(args: Array[String]): Unit = {
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment
    val text = env.readTextFile(input_path)
    val result = text.flatMap(_.split("\\s+")).map((_, 1)).groupBy(0).sum(1)
    result.writeAsCsv(output_path, "\n", ",").setParallelism(1)
    env.execute(WordCountScala.getClass.getName)
  }
}
